﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CoinComponent : MonoBehaviour
{
    GameObject parent;
    private void Awake()
    {
        parent = GameObject.Find("Gold");
    }

    private void OnEnable()
    {
        GetComponent<Rigidbody2D>().AddForce(new Vector2(Random.Range(-500,500),Random.Range(-500,500)));
    }

    public void End()
    {
        StartCoroutine(Wait());
    }
    IEnumerator Wait()
    {
        yield return new WaitForSeconds(2f);
        if (parent == null)
        {
            parent = GameObject.Find("Gold");
        }
        transform.SetParent(parent.transform);
        gameObject.SetActive(false);
    }
    public void Recycle()
    {
        transform.SetParent(parent.transform);
        gameObject.SetActive(false);
    }

    public void CoinSetParent(Transform parent)
    {
        transform.SetParent(parent);
        Debug.Log("父物体名:" + parent.name);
    }
}
